﻿

<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <link href="~/Content/layui/css/layui.css" rel="stylesheet" />
    <script src="~/Content/layui/layui.js"></script>
    <script src="~/Content/myjs/jquery-1.10.2.min.js"></script>
</head>
<body style="padding:40px 0 30px 80px;">
    @*padding:40px 0 30px 70px;    margin:0 90px 0 0;*@
<div class="layui-col-md8">
    <form class="layui-form layui-form-pane" lay-filter="form_add">

        <div class="layui-form-item">
            <label class="layui-form-label">耗材编号</label>
            <div class="layui-input-inline">
                <input type="text" name="GoodsId" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input" value="@ViewBag.onsumable.GoodsId" readonly="readonly" style="color:red;font-weight:600">
            </div>
            <label class="layui-form-label">耗材名称</label>
            <div class="layui-input-inline">
                <input type="text" name="Name" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input" value="@ViewBag.onsumable.Name">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">耗材类型</label>
            <div class="layui-input-inline ">
                <select name="CategoryId" id="myCategoryId">
                    @foreach (var item in @ViewBag.category)
                    {
                        <option value=@item.Id>@item.CategoryName</option>
                    }
                </select>
            </div>
            <label class="layui-form-label">耗材规格</label>
            <div class="layui-input-inline ">
                <input type="text" name="Specification" placeholder="请输入" autocomplete="off" class="layui-input" value="@ViewBag.onsumable.Specification">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">耗材数量</label>
            <div class="layui-input-inline">
                <input type="text" name="Num" lay-verify="required||number" placeholder="请输入" autocomplete="off" class="layui-input" value="@ViewBag.onsumable.Num">
            </div>
            <label class="layui-form-label">耗材单位</label>
            <div class="layui-input-inline ">
                <input type="text" name="Unit" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input" value="@ViewBag.onsumable.Unit">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">耗材单价</label>
            <div class="layui-input-inline">
                <input type="text" name="Money" placeholder="请输入" autocomplete="off" class="layui-input" value="@ViewBag.onsumable.Money">
            </div>
            <label class="layui-form-label">警告数量</label>
            <div class="layui-input-inline ">
                <input type="text" name="WarningNum" placeholder="请输入" autocomplete="off" class="layui-input" value="@ViewBag.onsumable.WarningNum">
            </div>
        </div>





        <div class="layui-form-item" style="text-align:center;margin:0 90px 0 0;">
            <button class="layui-btn" lay-submit="" lay-filter="formDemo">确认修改</button>
        </div>
    </form>
</div>

<script>
         //给下拉框赋值
        $('#myCategoryId').val(@ViewBag.onsumable.CategoryId);


        layui.use(['form', 'layedit', 'laydate'], function () {
            var form = layui.form
            var layedit = layui.layedit


            //自定义验证规则
            form.verify({
                maxlength: function (value) {
                    if (value.length >16) {
                        return '不能超过16个字符';
                    }
                }
            });
                //监听提交
            form.on('submit(formDemo)', function (data) {
                debugger;
                $.ajax({
                    url: '/Goods_Consumable/Update',
                    method: 'post',
                    data: data.field,
                    success: function (data) {

                        if (data == "ok") {
                            layer.alert("修改成功！");
                            setTimeout(function () {
                                //休眠1秒后页面跳转
                                window.location.href = "/Goods_Consumable/UpdateIndex?id="+@ViewBag.onsumable.Id+"";
                                //关闭当前弹框
                                //var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                //parent.layer.close(index); //再执行关闭
                            }, 2000);


                        } else {
                            layer.alert("修改失败");
                        }
                    }
                });
                return false;//防止页面跳转
            });
        });
</script>

</body>
</html>
